package hn.sigit.util.ladm;

import hn.sigit.logic.ladmshadow.Util;
import hn.sigit.model.hnd.ladmshadow.RRR;
import hn.sigit.model.ladm.administrative.LA_BAUnit;
import hn.sigit.model.ladm.administrative.LA_RRR;
import hn.sigit.model.ladm.administrative.dao.LA_BAUnitDAO;

import java.util.Date;
import java.util.Set;

public class LADM {
	public static void replaceRights(long baUnitId, Set<RRR> newRightsSet) {
		LA_BAUnit laBAUnit = LA_BAUnitDAO.loadBAUnitById(baUnitId);
		
		Date todaysDate = new Date();
		Set<LA_RRR> rightsSet = laBAUnit.getRrr();
		for (LA_RRR laRrr : rightsSet)
			laRrr.setEndLifespanVersion(todaysDate);
		
		for (RRR rrr : newRightsSet) {
			LA_RRR laRrr = Util.RRRToLA_RRR(rrr, laBAUnit);
			rightsSet.add(laRrr);
		}
		
		LA_BAUnitDAO.save(laBAUnit);
	}
}
